<?php
App::uses('AppController', 'Controller');

class ProposesController extends AppController {

	public $uses = array();
        
        function beforeFilter() {
            parent::beforeFilter();
            $AppInformation['Controller']['nameSingular'] = "proposta";
            $AppInformation['Controller']['namePlural'] = "Propostas";
            $this->set("AppInformation",$AppInformation);
        }
        
        function admin_index()
        {
            $this->layout = "admin";
            $Proposes = $this->Propose->find("all", array('recursive'=>2));
//            die(debug($Proposes));
            $this->set('Proposes',$Proposes);
        }
       
        function admin_view($id=null)
        {
            $this->layout = "admin";
            $Proposes = $this->Propose->find("all", array('recursive'=>2, 'conditions'=>array('client_id'=>2)));
//            die(debug($Proposes));
            $this->set('Proposes',$Proposes);
            $this->set('id',$id);
        }
        function export($id=null)
        {
            $this->layout = "pdf";
            $Proposes = $this->Propose->find("all", array('recursive'=>2, 'conditions'=>array('client_id'=>2)));
            $this->set('Proposes',$Proposes);
        }
//        function add()
//        {
//            $this->layout = "admin";
//            
//            if ($this->request->is('post'))
//            {
////                die(debug($this->request->data));
//                $this->Propose->save($this->request->data);
//                $this->Session->setFlash("Salvo com sucesso!");
//                
//                // Trocar 2 por getInsertLastInsert
//                $this->redirect(array('action'=>'edit',2));
//            }
//        }
        function admin_edit($id=null)
        {
            $this->layout = "admin";
            
            if ($this->request->is('post'))
            {
//                die(debug($this->request->data));
                $this->Propose->save($this->request->data);
                $this->Session->setFlash(__('Salvo com sucesso!'), 'Flashs/FlashMessengeGood');
            }
            else
            {
                $this->data = $this->Propose->find("first", array("recursive"=>2,"conditions"=>array("id"=>$id)));
            }
        }
        function admin_delete($id)
        {
            $this->Propose->delete($id);
            $this->Session->setFlash('Removido com sucesso.', 'default', array(), 'good');
            $this->redirect('/admin/pages');
        }
}
